Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make history file optional #16

Merged
merged 3 commits into from
Nov 8, 2019
Merged

Make history file optional #16

merged 3 commits into from
Nov 8, 2019

Conversation

vmax
Copy link
Contributor

@vmax vmax commented Nov 8, 2019

What is the goal of this PR?

Fix #7
Previously, Grakn Console would crash in case history file could not be created (possible reasons are user's home directory being non-present or mounted read-only)

What are the changes implemented in this PR?

  • Bump @graknlabs_protocol version
  • Make an adapter class which allows to .flush() history object regardless of whether it's backed by FileHistory or MemoryHistory
  • Resort to using in-memory history in case history file could not be created

@vmax vmax added this to the 1.0.2 milestone Nov 8, 2019
@@ -280,7 +288,7 @@ public final void close() {
session.close();
client.close();
try {
historyFile.flush();
history.flush();
Copy link

@marco-scoppetta marco-scoppetta Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given that we only flush once I think you can change the field history to be History rather than PersistentHistory and then in this try-catch you can just check if(history instanceof PeristentHistory) { ((PeristentHistory)history ).flush(); } , so that we don't need to create a fake empty class.

this.consoleReader.setHistory(this.historyFile);
PersistentHistory history;
try {
File file = new File(HISTORY_FILE);
Copy link

@marco-scoppetta marco-scoppetta Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here you can maybe use File.exists() rather than creating a history = new FlushableMemoryHistory(); in the catch block

Copy link

@marco-scoppetta marco-scoppetta Nov 8, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or you can also keep the catch, but I think it's important that we log with a warning the fact that we are falling back to an in-memory history, so maybe just add in the catch:

LOG.warn("An in-memory history will be used due to exception raised while trying to access history file: ", e.getMessage());
history = new FlushableMemoryHistory();

It's not a huge deal in this case, but it's generally important to be transparent with what's going on, i.e. don't secretly handle exceptions without warning if we're changing the expected behaviour

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@marco-scoppetta I think we actually want to fallback on any case on not being able to create/open a file. How could I utilize File.exists if creating a new file triggers IOException?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vmax vmax merged commit 19fe1b2 into typedb:master Nov 8, 2019
@vmax vmax deleted the make-history-file-optional branch November 8, 2019 12:58
vmax pushed a commit to typedb/typedb-driver-nodejs that referenced this pull request Nov 8, 2019
## What is the goal of this PR?
Fixes CI on `master` by:
- upgrading to latest `@graknlabs_console` to include typedb/typedb-console#16
- always running the build remotely
lolski pushed a commit to lolski/typedb-console that referenced this pull request Jun 9, 2021
…b#16)

## What is the goal of this PR?

Fixes first part of typedb/typedb#4803

## What are the changes implemented in this PR?

Upgrades `@build_bazel_rules_nodejs` to a version that includes a fix to 

````
DEBUG: /private/var/tmp/_bazel_<>/<>/external/bazel_skylib/lib.bzl:30:1: WARNING: lib.bzl is deprecated and will go away in the future, please directly load the bzl file(s) of the module(s) needed as it is more efficient.
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Graql shell crashes if a user doesn't have a home directory
2 participants